<?php
if( empty( $_SESSION ) )
{
	session_start();
}
header("Content-Type: text/html; charset=utf-8",true);

include("fckeditor.php");
include_once("../../includes/restrito.php");
include_once("../models/cls.pagina.php");

$oPagina = new pagina();

if( ! empty( $_GET["acao"] ) )
{
	switch( $_GET["acao"] )
	{
		case "editar" :
			$oPagina->select( $_GET["id"] );
			break;
			
		case "excluir" :
			$oPagina->delete( $_GET["id_delete"], "../views/frm.edicao.controle.php?id=".$_SESSION["id_edicao"]."&nome=".$_SESSION["nome_edicao"] );
			break;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>EDIÇÃO</title>
<link rel="stylesheet" type="text/css" href="../../includes/sistema.css"/>
<script type="text/javascript" src="../../includes/jquery.js"></script>
<script type="text/javascript" src="../../includes/jquery.mask.js"></script>
<script src="../../includes/panels.js" type="text/javascript"></script>
<script>
jQuery(function($){
	$("#ano").mask("999");
	$("#data").mask("99/99/9999");
})

function _salvar(){
	
	if(document.frm.id_pagina_indice.value=="")
	{
		alert("Por favor, selecione o sumário!");
		document.frm.id_pagina_indice.focus();
		return;
	}
	
	if(document.frm.id_colaborador.value=="")
	{
		alert("Por favor, selecionar o colaborador");
		document.frm.id_colaborador.focus();
		return;
	}
	
	if(document.frm.ordem.value=="")
	{
		alert("Informe a ordem deste conteúdo!");
		document.frm.ordem.focus();
		return;
	}


	if(document.frm.titulo.value=="")
	{
		alert("Por favor, informe o título da página!");
		document.frm.titulo.focus();
		return;
	}
		
	if(document.frm.resumo.value=="")
	{
		alert("Por favor, digite os resumo da página");
		document.frm.resumo.focus();
		return;
	}
	
	if(document.frm.detalhes.value=="")
	{
		alert("Por favor, digite os detalhes da página!");
		document.frm.detalhes.focus();
		return;
	}
		
	if(document.frm.capa.checked)
	{
		document.frm.capa.value = 1;
	}
	else
	{
		document.frm.capa.value = 0;
	}
	
	if(document.frm.indicar.checked)
	{
		document.frm.indicar.value = 1;
	}
	else
	{
		document.frm.indicar.value = 0;
	}

	if(document.frm.comentario.checked)
	{
		document.frm.comentario.value = 1;
	}
	else
	{
		document.frm.comentario.value = 0;
	}
	
	document.frm.submit();
}

function setValue(index)
{
	labelSelect = document.getElementById("id_pagina_indice").options[index].text;
	document.getElementById("titulo").value = labelSelect;
}
</script>
<link href="../../includes/panels.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="content">
    <h2>Adicionar página</h2>
    <hr size="1" noshade="noshade">
    	<form name="frm" method="post" action="../controllers/ctl.pagina.php">
        
          <table width="100%" border="0" align="center">
            <tr>
              <td >
              <h2>Edição: <?php echo $_SESSION["nome_edicao"]; ?></h2></td>
              <td  align="right"> Publicar na capa:
              <input name="capa" type="checkbox" class="form" <?php if($oPagina->capa == 1){ echo " checked"; } ?> />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
              
              <!--Ordem:-->
              <input name="ordem" type="hidden" class="form40px" value="<?php 
			  
			  if( empty( $oPagina->ordem ) )
			  {
			  	echo '0';
			  }
			  else
			  {
				  
				 echo $oPagina->ordem;
				  
			}
			  ?>"
              
              />
              
              </td>
            </tr>
            <tr>
              <td>Sumário: <br />
                <select name="id_pagina_indice" class="form100pc" id="id_pagina_indice" onchange="javascript:setValue(this.selectedIndex)">
                  <option value="">(escolha o sumário)</option>
                  <?php echo $oPagina->select_sumario( $_SESSION["id_edicao"] ); ?>
              </select></td>
              <td>Colaborador: <br />
                <select name="id_colaborador" class="form100pc" id="id_colaborador">
                  <option value="">(escolha o colaborador)</option>
                  <?php echo $oPagina->select_colaborador(); ?>
              </select></td>
            </tr>
            <tr>
              <td width="50%">Título
              <input name="titulo" type="text" id="titulo" class="form100pc" value="<?php echo $oPagina->titulo; ?>" /></td>
              <td width="50%">Subtítulo
              <input name="subtitulo" type="text" class="form100pc" value="<?php echo $oPagina->subtitulo; ?>" /></td>
            </tr>
            <tr>
              <td colspan="2">
              
              <div id="TabbedPanels1" class="TabbedPanels">
                <ul class="TabbedPanelsTabGroup">
                  <li class="TabbedPanelsTab" tabindex="0">Resumo</li>
                  <li class="TabbedPanelsTab" tabindex="0">Detalhes</li>
                </ul>
                <div class="TabbedPanelsContentGroup">
                  <div class="TabbedPanelsContent">

				<?php
                $sBasePath = $_SERVER['PHP_SELF'] ;
                $sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "editor" ) ) ;
                
                $oFCKeditor = new FCKeditor('resumo',300);
                $oFCKeditor->BasePath = $sBasePath;
                if( ! empty( $oPagina->resumo ) )
				{
					$oFCKeditor->Value = $oPagina->resumo;
				}
				else
				{
					$oFCKeditor->Value = "&nbsp;";
				}
                $oFCKeditor->Create();
                ?>              
                  </div>
                  <div class="TabbedPanelsContent">
                
				<?php
                $sBasePath = $_SERVER['PHP_SELF'] ;
                $sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "editor" ) ) ;
                
                $oFCKeditor = new FCKeditor('detalhes',600);
                $oFCKeditor->BasePath = $sBasePath;
				if( ! empty( $oPagina->detalhes ) )
				{
					$oFCKeditor->Value = $oPagina->detalhes;
				}
				else
				{
					$oFCKeditor->Value = "&nbsp;";
				}              
                $oFCKeditor->Create();
                ?>              

                  </div>
                </div>
              </div>
              
              </td>
            </tr>
            <tr>
              <td colspan="2"><table width="100%" border="0" align="center">
                <tr>
                  <td width="25%">
                    <input type="hidden" name="id" value="<?php echo $oPagina->id; ?>" />
                    <input type="hidden" name="id_revista" value="<?php echo $_SESSION["id_edicao"]; ?>" />
<input type="button" name="btnSalvar" value="SALVAR" class="formButton" onclick="_salvar()" />
                    <input name="btnVoltar" type="button" class="formButton" value="VOLTAR" onclick="javascript:history.back();" /></td>
                  <td width="75%" align="right">Indicar esta página para um amigo:
                    <input name="indicar" type="checkbox" class="form" <?php if($oPagina->indicar == 1){ echo " checked"; } ?> />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    Habilitar comentário:
                  <input name="comentario" type="checkbox" class="form" <?php if($oPagina->comentario == 1){ echo " checked"; } ?> /></td>
                </tr>
              </table></td>
            </tr>
          </table>
  </form>
</div>
<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
//-->
</script>
</body>
</html>